<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>审核页面</title>
    <script src="../../res/layui/layui.js" charset="utf-8" media="all"></script>
    <link rel="stylesheet" href="../../res/layui/css/layui.css" media="all">
    <script src="../../res/js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../res/js/xm-select.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form class="layui-form" action="" id="from">
    <input id="saId" name="saId" hidden></input>
    <div class="layui-form-item">
        <label class="layui-form-label">方案名称</label>
        <div class="layui-input-block">
            <input disabled type="text" class="layui-input" id="saName" name="saName" lay-verify="saName" class="layui-input" >
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否通过</label>
        <div class="layui-input-block">
            <input type="checkbox" id="state" checked="" name="state" lay-skin="switch" lay-filter="switchTest" lay-text="是|否">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">审核意见</label>
        <div class="layui-input-block">
            <textarea id="auExp" name="auExp" required lay-verify="required" style="margin: 0px; width: 358px; height: 143px;" placeholder="请填写审核意见" class="layui-textarea"></textarea>
        </div>
    </div>

    <div class="layui-form-item" id="zhuanjia">
        <label class="layui-form-label">专家姓名</label>
        <div class="layui-input-block" id="zhujianame"></div>
    </div>

    <div style="width: 216px; margin: 0;">
        <button type="button" class="layui-btn layui-btn-fluid" lay-submit lay-filter="formDemo">提交</button>
    </div>
</form>
<script>
    var form = null;
    layui.use(['form','laydate'], function(){

        form = layui.form;

        /*不为空判定*/
        form.verify({
            auExp:function(value){
                if(value==""){
                    return '必须要写反馈时间哦';
                };
            }
        });


        finByExpert();
        findById();
        //监听提交
        form.on('submit(formDemo)', function(data){
            var formData = new FormData(document.getElementById("from"));
            var url="../../ase/addSchemeAuditupdateSchemeExpert?id="+getQueryStringOne("id")
            $.ajax({
                url:url,
                type:"post",
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                dataType:"json",
                success:function(obj){
                    var i=0
                    if(obj.num==1){
                            layer.msg("成功",{
                                icon:1,
                                time:1000 //1秒关闭(如果不配置默认三秒)
                            },function(){
                                //关闭当前层
                                //当你在iframe页面关闭自身时
                                var index = parent.layer.getFrameIndex(window.name);//先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                //刷新父页面
                                parent.location.reload();
                            });

                    }else{
                        alert("操作失败")
                    }
                },
                error:function(e){
                }
            });
            return false;
        })
    });
    /*拿到页面传过来的id*/
    function getQueryStringOne(key) {
        var reg = new RegExp("(^|&)" + key + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return decodeURI(r[2]);
        return null;
    }
    //修改页面的赋值
    function findById(){
        var id=getQueryStringOne("id");
        var url="../../AtsSchemeAction/finbyid";
        var data={id:id};
        $.post(url,data,function(obj){
            $("#saName").val(obj.schemeName);
            form.render();
        },"json");
    }
    /* 教练员单选框赋值*/
    function finByExpert() {
        var url="../../AtsEmpExpert/finAlls";
        var data=null;
        $.post(url,data,function(obj){
            $.each(obj,function(index,item){
                $("#zhujianame").append("<input type='radio' id='expertName"+item.coachId+"' checked lay-verify='coachName' name='expertId' value='"+item.expertId+"' title='"+item.expertName+" '>");
            });
            form.render();
        },"json");
    }
</script>
</body>

</html>